package com.atguigu.spzx.product.service.impl;

import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.product.mapper.index.CategoryMapper;
import com.atguigu.spzx.product.service.CategoryService;
import com.atguigu.spzx.product.util.CategoryHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Mahone
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Cacheable(value = "category", key = "'all'")
    @Override
    public List<Category> selectAllOneData() {
        return categoryMapper.selectAllOneData();
    }

    @Cacheable(value = "categoryTree",key = "'all'")
    @Override
    public List<Category> findCategoryTree() {
        // 1.所有category列表中的所有数据
        List<Category> categoryList = categoryMapper.selectAllByList();
        // 2.创建CategoryHelper工具类，封装分类列表树结构
        return CategoryHelper.buildTree(categoryList);
    }
}
